package com.kaifamiao.high.thread;

/**
 * @author lucien-ma
 * @date 2021/10/9
 * @apiNote
 */
public class Demo13 {
    public static void main(String[] args) {
        ThreadLocal threadLocal = new ThreadLocal();
        Thread threadA = new Thread(() -> {
            threadLocal.set(1);
            try {
                Thread.currentThread().sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(threadLocal.get());
            threadLocal.remove();
        }, "线程A");

        Thread threadB = new Thread(() -> {
            threadLocal.set(2);
            threadLocal.remove();
        }, "线程B");

        threadA.start();
        threadB.start();
    }
}
